﻿using SuperCalendar.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SuperCalendar.Models;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;

namespace SuperCalendar.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for EventsTest and is intended
    ///to contain all EventsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class EventsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Insert
        ///</summary>
        [TestMethod()]
        public void InsertTest()
        {
            Event even = new Event();
            even.Title = "TESTEVENT";
            Events.Insert(even);
        }
        /// <summary>
        ///A test for InsertRange
        ///</summary>
        [TestMethod()]
        public void InsertRangeTest()
        {
            IEnumerable<Event> events = new Event[] { new Event("TESTEVENT"), new Event("TESTEVENT") };
            Events.InsertRange(events);
        }
        /// <summary>
        ///A test for GetAllEvents
        ///</summary>
        [TestMethod()]
        public void GetAllEventsTest()
        {
            List<Event> actual = Events.GetAllEvents();
            Assert.IsTrue(actual.Count > 0);
        }
        /// <summary>
        ///A test for Update
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            
            IEnumerable<Event> e = from ev in Events.GetAllEvents() where ev.Title.Equals("TESTEVENT") select ev;
            foreach(Event ev in e)
            {
                ev.Title = "TESTEVENT2";
                Events.Update(ev);
            }
            //Assert.IsTrue(Events.GetAllEvents)
        }
        
        

        /// <summary>
        ///A test for Delete
        ///</summary>
        [TestMethod()]
        public void DeleteTest()
        {
            IEnumerable<Event> e = from ev in Events.GetAllEvents() where ev.Title.Equals("TESTEVENT2") select ev;
            foreach (Event ev in e)
            {
                Events.Delete(ev);
            }
        }

       
    }
}
